{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "afcdc966",
   "metadata": {},
   "source": [
    "# Python 缩进\n",
    "缩进是指代码行开头的空格。\n",
    "\n",
    "在其他编程语言中，代码中的缩进只是为了可读性，而 Python 中的缩进非常重要。\n",
    "\n",
    "Python 使用缩进来表示代码块。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3990f6d6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Five is greater than two!\n"
     ]
    }
   ],
   "source": [
    "if 5 > 2:\n",
    "  print(\"Five is greater than two!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cae26b84",
   "metadata": {},
   "source": [
    "如果你跳过缩进，Python 会给你一个错误："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8ff21f56",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "expected an indented block (<ipython-input-2-a314491c53bb>, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-2-a314491c53bb>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    print(\"Five is greater than two!\")\u001b[0m\n\u001b[1;37m        ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n"
     ]
    }
   ],
   "source": [
    "if 5 > 2:\n",
    "print(\"Five is greater than two!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c9c722e",
   "metadata": {},
   "source": [
    "作为程序员，空格的数量取决于您，但必须至少为一个。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e9338025",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Five is greater than two!\n",
      "Five is greater than two!\n"
     ]
    }
   ],
   "source": [
    "if 5 > 2:\n",
    " print(\"Five is greater than two!\") \n",
    "if 5 > 2:\n",
    "        print(\"Five is greater than two!\") "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "593abff1",
   "metadata": {},
   "source": [
    "你必须在同一个代码块中使用相同数量的空格，否则 Python 会给你一个错误："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ec62870a",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unexpected indent (<ipython-input-5-7f4a16f35f16>, line 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-5-7f4a16f35f16>\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m    print(\"Five is greater than two!\")\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unexpected indent\n"
     ]
    }
   ],
   "source": [
    "if 5 > 2:\n",
    " print(\"Five is greater than two!\")\n",
    "   print(\"Five is greater than two!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "401d4fa3",
   "metadata": {},
   "source": [
    "# Python 变量"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c640a5ed",
   "metadata": {},
   "source": [
    "在 Python 中，当你给它赋值时会创建变量："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "513bb060",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = 5\n",
    "y = \"Hello, World!\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04c1bc00",
   "metadata": {},
   "source": [
    "Python 没有用于声明变量的命令。\n",
    "将在 Python 变量一章中了解有关变量的更多信息。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "220af8fa",
   "metadata": {},
   "source": [
    "# 注释"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69b07787",
   "metadata": {},
   "source": [
    "Python 具有用于代码文档的注释功能。\n",
    "注释以 # 开头，Python 会将行的其余部分渲染为注释："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5cdab915",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, World!\n"
     ]
    }
   ],
   "source": [
    "#This is a comment.\n",
    "print(\"Hello, World!\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {
    "height": "207px",
    "width": "230px"
   },
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
